//
//  XLVideoSetCell.m
//  XiangLove
//
//  Created by 宋振 on 2018/8/9.
//  Copyright © 2018年 BAOMIHUA.COM. All rights reserved.
//

#import "XLVideoSetCell.h"

#import "XLPersonCenterTool.h"

@interface XLVideoSetCell ()

/**
 图片
 */
@property (nonatomic, strong) UIImageView *  avatarImgV;

/**
 标题
 */
@property (nonatomic, strong) UILabel *  titleLbl;

/**
 时间
 */
@property (nonatomic, strong) UILabel *  creatTimeLbl;

/**
 审核状态
 */
@property (nonatomic, strong) UILabel *  auditingLbl;

/**
 被拒原因
 */
@property (nonatomic, strong) UILabel *  reasonLbl;

@end

@implementation XLVideoSetCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    
    if (self) {
        
        self.selectionStyle = UITableViewCellSeparatorStyleNone;
        
        /**
         绘制显示
         */
        [self initUI];
    }
    
    return self;
}


#pragma mark    - - - 绘制显示 - - -

/**
 设置显示
 */
- (void)initUI
{
    //头像
    [self addSubview:self.avatarImgV];
    
    [self.avatarImgV mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.mas_centerY);
        make.left.equalTo(self.mas_left).offset(kScale(15));
        make.size.mas_equalTo(CGSizeMake(70, 70));
    }];
    
    //标题
    [self addSubview:self.titleLbl];
    
    [self.titleLbl mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.avatarImgV.mas_top);
        make.left.equalTo(self.avatarImgV.mas_right).offset(kScale(10));
        make.width.mas_equalTo(178);
    }];
    
    //更新上传时间
    [self addSubview:self.creatTimeLbl];
    
    [self.creatTimeLbl mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.titleLbl.mas_bottom).offset(6);
        make.left.equalTo(self.titleLbl.mas_left);
        make.width.lessThanOrEqualTo(@178);
    }];
    
    //审核状态
    [self addSubview:self.auditingLbl];
    
    [self.auditingLbl mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.mas_centerY);
        make.right.equalTo(self.mas_right).offset(-kScale(11));
        make.height.mas_equalTo(25);
    }];
    
    //被拒原因
    [self addSubview:self.reasonLbl];
    
    [self.reasonLbl mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.titleLbl.mas_left);
        make.width.mas_equalTo(178);
        make.height.mas_equalTo(17);
        make.bottom.equalTo(self.avatarImgV.mas_bottom);
    }];
    
    
    //分割线
    UIView *lineView = [[UIView alloc] init];
    lineView.backgroundColor = RGB(238, 238, 238);
    [self addSubview:lineView];
    
    [lineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.mas_left).offset(95);
        make.right.equalTo(self.mas_right);
        make.bottom.equalTo(self.mas_bottom);
        make.height.mas_equalTo(0.5);
    }];
}





#pragma mark    - - - Tools - - -

/**
 设置文字显示 标题
 */
- (NSAttributedString *)setTitleAttributeText:(NSString *)text
{
    NSDictionary *dic = @{
                          NSKernAttributeName:@2,
                          NSFontAttributeName:[UIFont fontWithName:KFontNamePFMedium size:17],
                          NSForegroundColorAttributeName:RGB(17, 17, 17)
                          };
    
    NSAttributedString *attribute = [[NSAttributedString alloc] initWithString:text attributes:dic];
    
    return attribute;
}

/**
 设置文字显示 上传时间
 */
- (NSAttributedString *)setCreatAttributeText:(NSString *)text
{
    NSDictionary *dic = @{
                          NSKernAttributeName:@1,
                          NSFontAttributeName:[UIFont fontWithName:KFontNamePFMedium size:12],
                          NSForegroundColorAttributeName:RGB(153, 153, 153)
                          };
    
    NSAttributedString *attribute = [[NSAttributedString alloc] initWithString:text attributes:dic];
    
    return attribute;
}

/**
 设置文字显示 被拒原因
 */
- (NSAttributedString *)setReasonAttributeText:(NSString *)text
{
    NSDictionary *dic = @{
                          NSKernAttributeName:@1,
                          NSFontAttributeName:[UIFont fontWithName:KFontNamePFMedium size:12],
                          NSForegroundColorAttributeName:RGB(255, 58, 48)
                          };
    
    NSAttributedString *attribute = [[NSAttributedString alloc] initWithString:text attributes:dic];
    
    return attribute;
}

#pragma mark    - - - 获取数据 - - -

- (void)setModel:(XLCommitVideoSetModel *)model
{
    _model = model;
    
    if (model) {
        
        [self.avatarImgV sd_setImageWithURL:[NSURL URLWithString:K_DEFULT(model.PicUrl)] placeholderImage:[UIImage imageNamed:@""] completed:^(UIImage * _Nullable image, NSError * _Nullable error, SDImageCacheType cacheType, NSURL * _Nullable imageURL) {
            
            
            
        }];
        
    }
    
    self.reasonLbl.hidden = YES;
    //标题需要根据反馈信息 师傅展示两行
    if ([model.Status isEqualToString:@"3"]) {
        
        
        self.titleLbl.numberOfLines = 1;
        
        self.reasonLbl.hidden = NO;
        self.reasonLbl.attributedText = [self setReasonAttributeText:K_DEFULT(model.Reason)];
        self.auditingLbl.text = @"未通过";
        self.auditingLbl.textColor = RGB(255, 58, 48);
        
    }else if ([model.Status isEqualToString:@"2"]){
        
        self.auditingLbl.text = @"审核中";
        self.auditingLbl.textColor = RGB(243, 186, 32);
        
    }
    
    self.creatTimeLbl.attributedText = [self setCreatAttributeText:K_DEFULT(model.CreateTime)];
    
    self.titleLbl.attributedText = [self setTitleAttributeText:K_DEFULT(model.Title)];
}



#pragma mark    - - - Getter - - -

//头像
- (UIImageView *)avatarImgV
{
    if (!_avatarImgV) {
        self.avatarImgV = [[UIImageView alloc] init];
        self.avatarImgV.backgroundColor = [UIColor grayColor];
        self.avatarImgV.layer.cornerRadius = 3;
        self.avatarImgV.layer.masksToBounds = YES;
        self.avatarImgV.image = [[UIImage imageNamed:@"me_pic_yhdj"] imageWithRenderingMode:(UIImageRenderingModeAlwaysOriginal)];
    }
    
    return _avatarImgV;
}

//标题
- (UILabel *)titleLbl
{
    if (!_titleLbl) {
        self.titleLbl = [[UILabel alloc] init];
        self.titleLbl.numberOfLines = 2;
    }
    
    return _titleLbl;
}

//上传时间
- (UILabel *)creatTimeLbl
{
    if (!_creatTimeLbl) {
        self.creatTimeLbl = [[UILabel alloc] init];
//        self.creatTimeLbl.attributedText = [self setCreatAttributeText:@"上传时间：2018.05.08"];
    }
    
    return _creatTimeLbl;
}

//审核状态
- (UILabel *)auditingLbl
{
    if (!_auditingLbl) {
        self.auditingLbl = [[UILabel alloc] init];
        self.auditingLbl.font = [UIFont fontWithName:KFontNamePFMedium size:15];
        self.auditingLbl.textColor = RGB(243, 186, 32);
    }
    
    return _auditingLbl;
}

//被拒原因 （如果有被拒原因 标题只显示一行，如果没有被拒原因就相对布局，被拒原因隐藏）
- (UILabel *)reasonLbl
{
    if (!_reasonLbl) {
        self.reasonLbl = [[UILabel alloc] init];
//        self.reasonLbl.attributedText = [self setReasonAttributeText:@"请上传有效标题"];
    }
    return _reasonLbl;
}


@end
